package pres.wchen.oa.cor.shiro.shiro.realm;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.apache.shiro.subject.PrincipalCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @作者： wchen
 * @描述：
 * @创建时间： 2018/1/16 20:32
 * @版本：Copyright 2018, Inc. All Rights Reserved.
 * @修改信息：
 */
public class MyCredentialsMatcher extends SimpleCredentialsMatcher {
    private static final Logger logger = LoggerFactory.getLogger(MyCredentialsMatcher.class);

    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        logger.info("------------密码验证ing------------");
        UsernamePasswordToken uToken = (UsernamePasswordToken) token;
        String password = new String(uToken.getPassword());
        String realPassword = info.getCredentials().toString();
        PrincipalCollection principalCollection = info.getPrincipals();
        logger.info("------------密码验证ing------------ "+this.equals(password, realPassword));
        return this.equals(password, realPassword);
    }
}
